/**
 * @file 跟踪窗口接口
 *
 * 跟踪窗口接口
 *
 * @author wq1977@gmail.com
 */
 
#ifndef __TRACE_FORM_H__
#define __TRACE_FORM_H__

#include "wx/wx.h"
#include "wx/datetime.h"
#include "mycanvas.h"

WX_DECLARE_STRING_HASH_MAP(long, StrLongHash);

enum TraceLevel{
    TL_BAD,
    TL_ERROR,
    TL_MESSAGE,
    TL_SIP_MESSAGE,
    TL_MESSAGE_RETRANS,
    TL_MATCH_RULE,
    TL_WARNING,
};

WX_DEFINE_ARRAY_INT(int, IntArray);

class wxTraceFormEvent : public wxNotifyEvent
{
  DECLARE_DYNAMIC_CLASS(wxTraceFormEvent);    
 public:
  wxTraceFormEvent(){};
 wxTraceFormEvent(const wxString& str, int level,  wxEventType commandType = wxEVT_NULL,
		  int id = 0): wxNotifyEvent(commandType, id)
    {
      LogStr = str;
      Level = level;
      when = wxDateTime::UNow();
    }
 wxTraceFormEvent(const wxTraceFormEvent& event): wxNotifyEvent(event)
  {
    LogStr=event.LogStr;
    Level=event.Level;
    when=event.when;
  }
  virtual wxEvent *Clone() const
  { return new wxTraceFormEvent(*this); }
  wxString GetLogStr(){return LogStr;};
  int GetLevel(){return Level;};
  wxDateTime GetWhen(){return when;};
 private:
    wxString LogStr;
    int Level;
    wxDateTime when;
};
typedef void (wxObject::*wxTraceFormEventFunction)
                                        (wxEvent&);

BEGIN_DECLARE_EVENT_TYPES()
    DECLARE_EVENT_TYPE(wxEVT_COMMAND_TRACE_FORM, wxEVT_USER_FIRST+1)
END_DECLARE_EVENT_TYPES()

#define EVT_TRACE_FORM(id, fn) DECLARE_EVENT_TABLE_ENTRY((const int&)wxEVT_COMMAND_TRACE_FORM, id, -1, (wxTraceFormEventFunction) (wxEventFunction) \
  (wxTraceFormEventFunction) & fn,\
  (wxObject *) NULL ),


class TraceForm: public wxMDIChildFrame
{
public:
    TraceForm(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
    ~TraceForm();
    void SetTraceSource(const wxWindow*src){TraceSrc = src;};
    void AppendTraceTarget(int t){TraceTarget.push_back(t); UpdateTitle();};
    bool IsTracingMe(int index);
    void UpdateTitle();
    void Clear();
    void Trace(int Level, const wxString& Value, bool lock=true);
    void OnTraceForm(wxTraceFormEvent& event);
    void OnMouseLeftDown( wxMouseEvent &event );

    wxTextCtrl *m_Text;
    MyCanvas  *m_msgflow;

private:
    const wxWindow* TraceSrc;
    IntArray TraceTarget;


    void OnClose(wxCloseEvent& event);
    DECLARE_EVENT_TABLE()

};

#endif

